/* 公用方法 */
import config from "@/app.config.js";
import resource from "@/common/js/resource.js";

let $GLOBAL;

export default {
	// 初始化数据
	initData(globalData) {
		if (config.debug) console.log('==== global.js 初始化公共数据 in ====')
		$GLOBAL = globalData;
		this.getNavList();
		this.getSite();
	},
	getSite() {
		if ($GLOBAL.site && $GLOBAL.site._id) return;
		vk.callFunction({
			url: 'client/lzy_common/pub.app.getInfo'
		}).then((res) => {
			console.log('网站信息', res)
			$GLOBAL.site = res.item;
			resource.topUrl = res.item.img1[0];
			resource.logo = res.item.img2[0];
			resource.lhfjBg = res.item.img3[0];
			uni.$emit('site-init')
		});
	},
	// 获取导航列表
	getNavList() {
		if ($GLOBAL.navList && $GLOBAL.navList.length > 0) return;
		vk.callFunction({
			url: 'client/lzy_common/pub.nav.getList',
			title: '请求中...',
			data: {
				// is_index: true
			},
		}).then(res => {
			console.log('导航列表', res)
			$GLOBAL.navList = res.rows.filter(item => item.is_index);
			$GLOBAL.navNavList = res.rows.filter(item => item.position == 'nav');
			$GLOBAL.lhfjNavList = res.rows.filter(item => item.position == 'lhfj');
			uni.$emit('nav-init')
		});
	},
}